// import axios from 'axios';
import app from '@/main';
import {ElMessage} from 'element-plus';

const {baseUrl, serviceUrl} = require('./api');
const service = {
    //处理外发请求
    doRequest(url, method, data) {
        const headers = {};
        return new Promise((resolve, reject) => {
            app.axios({
                url: serviceUrl + baseUrl + url,
                method,
                data,
                headers
            }).then((response) => {
                const data = response.data;
                if (data.code !== 1) {
                    ElMessage({
                        showClose: false,
                        message: data.msg,
                        type: 'warning',
                    });
                }
                resolve(data);
            }).catch((err) => {
                ElMessage({
                    showClose: false,
                    message: err.message,
                    type: 'error',
                });
                reject(err);
            });
        })
    },
    //执行post
    doPost(url, data) {
        return service.doRequest(url, 'POST', data);
    }
};
export {service};